<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
<!--    <meta http-equiv="X-UA-Compatible" content="IE=edge">-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
    <title>汽车租赁</title>
    <meta name="description" content="汽车租赁">
    <meta name="keywords" content="汽车租赁">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>发布租车<small>店铺发布租车列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>发布租车</el-breadcrumb-item>
            <el-breadcrumb-item>店铺发布租车列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                店铺名称：<el-input placeholder="店铺名称" v-model="pagination.shopName" style="width: 200px;" class="filter-item"></el-input>
                汽车品牌名称：<el-input placeholder="汽车品牌名称" v-model="pagination.carBrandName" style="width: 200px;" class="filter-item"></el-input>
                汽车名称：<el-input placeholder="汽车名称" v-model="pagination.carName" style="width: 200px;" class="filter-item"></el-input>
                汽车类型：<el-input placeholder="汽车类型" v-model="pagination.type" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="id" align="center" label="发布编号" v-if="show"></el-table-column>
                <el-table-column prop="shopName" label="店铺名称" align="center"></el-table-column>
                <el-table-column prop="carBrandName" label="汽车品牌名称" align="center"></el-table-column>
                <el-table-column prop="carName" label="汽车名称" align="center"></el-table-column>
                <el-table-column prop="type" label="汽车类型" align="center"></el-table-column>
                <el-table-column prop="gears" label="汽车挡位" align="center"></el-table-column>
                <el-table-column prop="site" label="汽车座位数" align="center"></el-table-column>
                <el-table-column prop="dailyrent" label="汽车日租金" align="center"></el-table-column>
                <el-table-column  label="汽车图片" width="200" align="center">
                    <!--插入图片链接的代码-->
                    <template slot-scope="scope">
                        <img :src="scope.row.img" alt style="width: 50px;height:50px">
                    </template>
                </el-table-column>
                <el-table-column prop="rentNum" label="可预约数" align="center"></el-table-column>
                <el-table-column prop="createTime" label="可预约开始时间" align="center"></el-table-column>
                <el-table-column prop="endTime" label="可预约结束时间" align="center"></el-table-column>


                <el-table-column label="操作" align="center" width="200px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="handleSizeChange"
                        :page-sizes="[5, 10, 20, 50]"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 添加标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增发布" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="发布租赁信息" name="first">
                                <el-form label-position="right" label-width="130px">
                                    <el-row>

                                        <el-col :span="24">
                                            <el-form-item label="可预约汽车数量">
                                                <el-input v-model="formData.rentNum"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="可预约开始时间">
                                                <!--       在el-for中添加时间模块       -->
                                                <el-date-picker type="datetime" placeholder="选择日期" v-model="formData.createTime"
                                                                style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="可预约结束时间">
                                                <!--       在el-for中添加时间模块       -->
                                                <el-date-picker type="datetime" placeholder="选择日期" v-model="formData.endTime"
                                                                style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="汽车品牌信息" name="second">
                                <div class="checkScrol1">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>汽车品牌名称</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="a in carbrandData">
                                            <td>
                                                <input :id="a.id" v-model="carbrandIds" type="checkbox" :value="a.id">
                                            </td>
                                            <td><label :for="a.id">{{a.name}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="汽车信息" name="third">
                                <div class="checkScrol2">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>汽车名称</th>
                                            <th>汽车类型</th>
                                            <th>汽车车牌号</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="b in carData">
                                            <td>
                                                <input :id="b.carId" v-model="carIds" type="checkbox" :value="b.carId">
                                            </td>
                                            <td><label :for="b.carId">{{b.carName}}</label></td>
                                            <td><label :for="b.carId">{{b.type}}</label></td>
                                            <td><label :for="b.carId">{{b.plateNumber}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="店铺信息" name="fourth">
                                <div class="checkScrol3">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>店铺名称</th>
                                            <th>店铺手机号</th>
                                            <th>店铺地址</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in shopData">
                                            <td>
                                                <input :id="c.shopId" v-model="shopIds" type="checkbox" :value="c.shopId">
                                            </td>
                                            <td><label :for="c.shopId">{{c.shopName}}</label></td>
                                            <td><label :for="c.shopId">{{c.phone}}</label></td>
                                            <td><label :for="c.shopId">{{c.address}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
<!--            编辑添加-->
            <div class="add-form">
                <el-dialog title="编辑发布" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="发布租赁信息" name="first">
                                <el-form label-position="right" label-width="130px">
                                    <el-row>

                                        <el-col :span="24">
                                            <el-form-item label="可预约汽车数量">
                                                <el-input v-model="formData.rentNum"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="可预约开始时间">
                                                <!--       在el-for中添加时间模块       -->
                                                <el-date-picker type="datetime" placeholder="选择日期" v-model="formData.createTime"
                                                                style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="可预约结束时间">
                                                <!--       在el-for中添加时间模块       -->
                                                <el-date-picker type="datetime" placeholder="选择日期" v-model="formData.endTime"
                                                                style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="汽车品牌信息" name="second">
                                <div class="checkScrol1">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>汽车品牌名称</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="a in carbrandData">
                                            <td>
                                                <input :id="a.id" v-model="carbrandIds" type="checkbox" :value="a.id">
                                            </td>
                                            <td><label :for="a.id">{{a.name}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="汽车信息" name="third">
                                <div class="checkScrol2">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>汽车名称</th>
                                            <th>汽车类型</th>
                                            <th>汽车车牌号</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="b in carData">
                                            <td>
                                                <input :id="b.carId" v-model="carIds" type="checkbox" :value="b.carId">
                                            </td>
                                            <td><label :for="b.carId">{{b.carName}}</label></td>
                                            <td><label :for="b.carId">{{b.type}}</label></td>
                                            <td><label :for="b.carId">{{b.plateNumber}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                            <el-tab-pane label="店铺信息" name="fourth">
                                <div class="checkScrol3">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>店铺名称</th>
                                            <th>店铺手机号</th>
                                            <th>店铺地址</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in shopData">
                                            <td>
                                                <input :id="c.shopId" v-model="shopIds" type="checkbox" :value="c.shopId">
                                            </td>
                                            <td><label :for="c.shopId">{{c.shopName}}</label></td>
                                            <td><label :for="c.shopId">{{c.phone}}</label></td>
                                            <td><label :for="c.shopId">{{c.address}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            show:false,
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null,//查询条件
                shopName:"",
                carBrandName:"",
                carName:"",
                type:"",
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {
                car:[],
                shop:[],
                carbrand:[]
            },//表单数据
            carIds:[],
            shopIds:[],
            carbrandIds:[],
            carData:[],//新增和编辑表单中对应的汽车列表数据
            carbrandData:[],//新增和编辑表单中对应的汽车品牌列表数据
            shopData:[],//新增和编辑表单中对应的店铺列表数据

            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//编辑表单是否可见
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {

            // //添加发布
                // 添加
                handleAdd () {
                    axios.post(`/openrend/addOpenRend?carIds=${this.carIds}&carbrandIds=${this.carbrandIds}&shopIds=${this.shopIds}`,this.formData).then(resp =>{
                        if (resp.data.flag){
                            //弹出提示信息
                            this.$message({
                                message: resp.data.message,
                                type: 'success'
                            });
                            this.dialogFormVisible=false;
                            this.findPage();
                        }else{
                            console.log('失败');
                            //弹出失败信息
                            this.$message().error(resp.data.message);
                        }
                    })
                },
            //编辑汽车品牌
            handleEdit() {
                axios.post(`/openrend/updateOpenRend?carIds=${this.carIds}&carbrandIds=${this.carbrandIds}&shopIds=${this.shopIds}`,this.formData).then(resp =>{
                    if (resp.data.flag) {
                        //弹出提示信息
                        this.$message({
                            message: resp.data.message,
                            type: 'success'
                        });
                        this.dialogFormVisible4Edit = false;
                        this.findPage();
                    }else{
                        console.log('失败');
                        //弹出失败信息
                        this.$message().error(resp.data.message);
                    }
                })
            },
            //分页查询
            findPage() {
                axios.post("/openrend/selectPage",this.pagination).then((response) => {
                    console.log(response);
                    this.dataList=response.data.data.page.list;
                    this.pagination.total=res.data.data.page.totalCount;
                })
            },
            //调整每页记录数
            handleSizeChange(val) {
                this.pagination.pageSize = val
                this.findPage()
            },
            //重置表单
            resetForm() {
                this.formData={};
            },
            loadCar(){
                axios.get("/car/findAllCar").then(resp =>{
                    if (resp.data.flag){
                        this.carData=resp.data.data;

                    }else{
                        this.$message.error(resp.data.message);
                    }

                })
            },
            loadCarbrand(){
                axios.get("/carbrand/findAllCarbrand").then(resp =>{
                    if (resp.data.flag){
                        this.carbrandData=resp.data.data;

                    }else{
                        this.$message.error(resp.data.message);
                    }

                })
            },
            loadShop(){
                axios.get("/shop/findAllShop").then(resp =>{
                    if (resp.data.flag){
                        this.shopData=resp.data.data;

                    }else{
                        this.$message.error(resp.data.message);
                    }

                })
            },
            //弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible=true;
                this.loadCarbrand();
                this.loadCar();
                this.loadShop();
            },
            //弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit=true;
                this.loadCarbrand();
                this.loadCar();
                this.loadShop();
                axios.get("/openrend/getOpenRendById/"+row.id).then(resp=>{
                    console.log(resp);
                    this.formData=resp.data.data.openrend;
                    this.carIds=resp.data.data.carIds;
                    this.carbrandIds=resp.data.data.carbrandIds;
                    this.shopIds=resp.data.data.shopIds;
                })
            },
            //切换页码显示分页信息
            handleCurrentChange(currentPage) {
                this.pagination.currentPage=currentPage;
                this.findPage();
            },
            // 删除发布
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/openrend/deleteOpenrend/"+row.id).then(resp=>{
                        if (resp.data.flag){
                            //弹出提示信息
                            this.$message({
                                message: resp.data.message,
                                type: 'success'
                            });
                            this.findPage();
                        }else{
                            //弹出失败信息
                            this.$message().error(resp.data.message);
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
        }
    })
</script>
</html>